<template>
  <div class="w-210px h-250px rounded-4px relative">
    <!-- <div
      class="absolute left-13px top-16px text-16px leading-24px z-20 font-medium"
      style="color: #150f0b"
    >
      新款推荐
    </div> -->
    <n-carousel autoplay :interval="2000">
      <img
        v-for="newProduct in newProducts"
        :key="newProduct.id"
        class="w-full h-full cursor-pointer rounded-4px"
        :src="newProduct.imgUrl"
        alt=""
        @click="godetail(newProduct)"
      />
    </n-carousel>
  </div>
</template>

<script setup lang="ts">
import useHttp from '@renderer/utils/http'
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()
const newProducts = ref<any>([])
const godetail = (spu) => {
  router.push({ name: 'Detail', params: { id: spu.id } })
}
onMounted(async () => {
  const { data: res } = await useHttp('/new/c/list').get().json()
  if (res?.value?.code === 200) {
    newProducts.value = res.value.data.map((r) => {
      const { imgs, poster } = r
      if (poster) {
        r.imgUrl = poster
      } else if (imgs) {
        r.imgUrl = JSON.parse(imgs)?.[0]?.url
      }
      return r
    })
  }
})
</script>

<style scoped></style>
